<?php

session_start(); 
$to=$_POST['cuid'];
$from=$_SESSION['username'];
$msg=$_POST['messg'];
if(!$_POST['messg'])
{
$msg=" ";
}
//$username='gek1123';
//$msg='Hi, I want to connect with you!!!!!!!!!!!';
//$from='gip2103';
//$to='xw2174';
//$accepted='No';

$conn = oci_connect("gaurav", "gaurav", "xe"); 

//echo 'Username'.$msg.$from.$to;

$query = "INSERT INTO Messages (MessageID,Mesg,FromCUID,ToCUID) VALUES(msgseq.nextval,:message,:fromcuid,:tocuid)";

//echo 'Message'.$cuid.$password1.$fname.$mname.$lname.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber.$sex.$deptid.$role;

$bindargs = array();
array_push($bindargs, array('MESSAGE', $msg, -1));
array_push($bindargs, array('FROMCUID', $from, -1));
array_push($bindargs, array('TOCUID', $to, -1));


$r = db_execute_statement($conn, $query, $bindargs);

header('Location: /ProfessorHomePageMessage.php');

function db_execute_statement($conn, $statement, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  return($r);
}
?>